//
//  ByBallBetDetailValueView.m
//  caipiao_ios
//
//  Created by mc on 2018/8/15.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByBallBetDetailValueView.h"

@implementation ByBallBetDetailValueView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        CGFloat width = frame.size.width / 3.0;
        UILabel *sessionLabel = [[UILabel alloc] init];
        [self addSubview:sessionLabel];
        [sessionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.bottom.equalTo(self.mas_centerY).offset(-2);
            make.size.mas_equalTo(CGSizeMake(width , 20));
        }];
        sessionLabel.text = @"周二001";
        sessionLabel.textColor = [UIColor lightGrayColor];
        sessionLabel.textAlignment = NSTextAlignmentCenter;
        sessionLabel.font = FONT(11);
        
        
        UILabel *titleLabel = [[UILabel alloc] init];
        [self addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.top.equalTo(sessionLabel.mas_bottom).offset(0);
            make.size.mas_equalTo(CGSizeMake(width , 30));
        }];
        titleLabel.text = @"罗奇代尔 VS 福利特";
        titleLabel.font = FONT(11);
        titleLabel.textColor = [UIColor blackColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.numberOfLines = 0;
        
        UILabel *resultLabel = [[UILabel alloc] init];
        [self addSubview:resultLabel];
        [resultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(sessionLabel.mas_right).offset(0);
            make.top.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(width, Table_Height));
        }];
        resultLabel.font = FONT(12);
        resultLabel.textAlignment =  NSTextAlignmentCenter;
        resultLabel.textColor = [UIColor redColor];
        resultLabel.text = @"";
        resultLabel.numberOfLines = 0;
        
        UILabel *contentLabel = [[UILabel alloc] init];
        [self addSubview:contentLabel];
        [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(0);
            make.top.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(width, Table_Height));
        }];
        contentLabel.font = FONT(12);
        contentLabel.textAlignment =  NSTextAlignmentCenter;
        contentLabel.textColor = [UIColor blackColor];
        contentLabel.text = @"";
        contentLabel.numberOfLines = 0;
        
        
        self.sessionLabel = sessionLabel;
        self.titleLabel = titleLabel;
        self.resultLabel = resultLabel;
        self.contentLabel = contentLabel;
        
    }
    return self;
}


- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    self.sessionLabel.text = _netModel.num;
    self.titleLabel.text = [NSString stringWithFormat:@"%@(%@) VS %@", _netModel.h_cn,_netModel.rq?:@"",_netModel.a_cn];
    self.resultLabel.text = netModel.game_Result;
    self.contentLabel.text = netModel.bet_Content;
    
    if ([netModel.game_Result isEqualToString:@"未开奖"]) {
        self.resultLabel.textColor = rgba(51, 51, 51, 1);
    }
    
    NSArray *chooseArr = [netModel.game_Result componentsSeparatedByString:@","]; // 赛果内容
    NSArray *bingoArr = [netModel.bet_Content componentsSeparatedByString:@","]; // 投注内容
    
    NSMutableAttributedString *bingoaAttStr = [[NSMutableAttributedString alloc] initWithString:[bingoArr componentsJoinedByString:@"\n"] attributes:@{NSForegroundColorAttributeName:rgba(51, 51, 51, 1)}];
    for (int i = 0; i <chooseArr.count; i++) {
        
        NSString *choose = chooseArr[i];
        
        NSArray *chooseTempArr = [choose componentsSeparatedByString:@"("];
        
        for (int j = 0; j< bingoArr.count; j++) {
            
            NSString *subBingoString =bingoArr[j];
            
            NSArray *ar = [subBingoString componentsSeparatedByString:@"("];
            
            if ([chooseTempArr[0] isEqualToString:ar[0]]) {
                [bingoaAttStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[[bingoaAttStr string] rangeOfString:subBingoString]];
                continue;
            }
        }
    }
    
    
    self.resultLabel.text = [chooseArr componentsJoinedByString:@"\n"];
    self.contentLabel.attributedText = bingoaAttStr;
    
    CGSize sizeOne = [self.contentLabel sizeThatFits:CGSizeMake(SCREEN_WIDTH/3, self.contentLabel.height)];
    if (sizeOne.height >= Table_Height) {
        self.contentLabel.font = [UIFont systemFontOfSize:8];
    }
    
    
    
    
    
    
}

@end
